package cn.iocoder.yudao.module.eval.service.venueequipment;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.eval.controller.admin.venueequipment.vo.*;
import cn.iocoder.yudao.module.eval.dal.dataobject.venueequipment.VenueEquipmentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.eval.dal.mysql.venueequipment.VenueEquipmentMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.eval.enums.ErrorCodeConstants.*;

/**
 * 场地设备 Service 实现类
 *
 * @author 龙头企业
 */
@Service
@Validated
public class VenueEquipmentServiceImpl implements VenueEquipmentService {

    @Resource
    private VenueEquipmentMapper venueEquipmentMapper;

    @Override
    public Long createVenueEquipment(VenueEquipmentSaveReqVO createReqVO) {
        // 插入
        VenueEquipmentDO venueEquipment = BeanUtils.toBean(createReqVO, VenueEquipmentDO.class);
        // 显式设置deleted字段默认值
        venueEquipment.setDeleted(false);
        venueEquipmentMapper.insert(venueEquipment);

        // 返回
        return venueEquipment.getId();
    }

    @Override
    public void updateVenueEquipment(VenueEquipmentSaveReqVO updateReqVO) {
        // 校验存在
        validateVenueEquipmentExists(updateReqVO.getId());
        // 更新
        VenueEquipmentDO updateObj = BeanUtils.toBean(updateReqVO, VenueEquipmentDO.class);
        venueEquipmentMapper.updateById(updateObj);
    }

    @Override
    public void deleteVenueEquipment(Long id) {
        // 校验存在
        validateVenueEquipmentExists(id);
        // 删除
        venueEquipmentMapper.deleteById(id);
    }

    @Override
        public void deleteVenueEquipmentListByIds(List<Long> ids) {
        // 删除
        venueEquipmentMapper.deleteByIds(ids);
        }


    private void validateVenueEquipmentExists(Long id) {
        if (venueEquipmentMapper.selectById(id) == null) {
            throw exception(VENUE_EQUIPMENT_NOT_EXISTS);
        }
    }

    @Override
    public VenueEquipmentDO getVenueEquipment(Long id) {
        return venueEquipmentMapper.selectById(id);
    }

    @Override
    public PageResult<VenueEquipmentDO> getVenueEquipmentPage(VenueEquipmentPageReqVO pageReqVO) {
        return venueEquipmentMapper.selectPage(pageReqVO);
    }

}